package com.funny.rabbitmq.helloworld;

import com.funny.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Consumer {

    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();

        /**
         * 消费者消费参数
         * 1.消费队列名称
         * 2.是否自动应答
         * 3.消费者未成功消费的回调
         * 4.消费者取消消费的回调
         */
        channel.basicConsume(QUEUE_NAME, false, (consumerTag, message) -> {
            log.info("consumerTag={}, message={}", consumerTag, new String(message.getBody()));
        }, consumerTag -> {
            log.info("consumerTag={}", consumerTag);
        });
        System.out.println("消息消费成功");

    }


    private static void doWork(String task) throws InterruptedException {
        for (char ch: task.toCharArray()) {
            if (ch == '.') Thread.sleep(1000);
        }
    }
}
